#! /bin/sh

# deploy a new server for domain monitor
# 0. python>=2.7  git
# 1. redis     task broker
# 2. mongodb   task result
# 3. celery flower   task scheudle,and task monitor
# 4. supervisor(>=3.0)
yum -y update
yum -y install git make gcc python-devel

mkdir install_need_files;cd install_need_files


# 1. install redis by source code, start by /usr/local/redis-3.0.5/src/redis-server /usr/local/redis-3.0.5/redis.conf
wget http://download.redis.io/releases/redis-3.0.5.tar.gz
tar -zxvf redis-3.0.5.tar.gz
cd redis-3.0.5
make
cd ..
cp -r redis-3.0.5 /usr/local/

# 2. install mongodb
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.7.tgz
tar -zxvf mongodb-linux-x86_64-rhel62-3.0.7.tgz
cp -r mongodb-linux-x86_64-rhel62-3.0.7 /usr/local

# 3. install pip
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-18.3.2.tar.gz https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
tar -zxvf setuptools-18.3.2.tar.gz
tar -zxvf pip-7.1.2.tar.gz
cd setuptools-18.3.2; python setup.py install;cd ..
cd pip-7.1.2; python setup.py install;cd ..


# python requirements for redis, mongodb
wget https://pypi.python.org/packages/source/p/pymongo/pymongo-3.0.3.tar.gz#md5=0425d99c2a453144b9c95cb37dbc46e9
tar -zxvf pymongo-3.0.3.tar.gz
cd pymongo-3.0.3;python setup.py install;cd ..

pip install redis==2.10.3 celery==3.1.19 flower==0.8.3 supervisor beautifulsoup4

# supervisor configuration
mkdir -p /etc/supervisor/conf.d; echo_supervisord_conf > /etc/supervisor/supervisord.conf